package protocol.work.connection.http;

import org.apache.commons.logging.Log;

import protocol.common.util.CJLog;
import protocol.common.util.StringKit;
import protocol.data.util.JedisPoolUtil;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

public abstract class AbstractHandleWork{
	protected Log logger = CJLog.getLogConsole();
	
	protected String queryPrefix;
	
	protected JedisPool jedisPool;
	
	public AbstractHandleWork(String channel){
		this.jedisPool = JedisPoolUtil.getJedisPool();
		this.queryPrefix = channel + "-Http-SendData";
	}
	
	public void exceptionHandle(Exception ex){
		logger.error(StringKit.getExceptionInfo(ex));
	}
	
	protected void returnJedis(Jedis jedis) {
		if (jedis != null)
			if (jedis.isConnected())
				this.jedisPool.returnResource(jedis);
			else
				this.jedisPool.returnBrokenResource(jedis);
	}

	protected Jedis getJedis() {
		return (Jedis) this.jedisPool.getResource();
	}
	
}
